home *** CD-ROM | disk | FTP | other *** search
- /**--------------------------------------------------------------
- ** Ralcool Software - Simulation - 1988
- **--------------------------------------------------------------
- ** MODULE : PARSE.C
- ** PURPOSE : <t> parse out file into interpreter structure
- ** PROGRAMMER : Sandy
- ** START DATE : 11/28/1988 06:57:38
- ** DESCRIPTION:
- ** :
- ** :
- **==============================================================
- **/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dtypes.h>
- #include <conio.h>
-
- #include "shop.h"
- #include "code.h"
-
- #include "parse.h"
-
- char vars[100][20];
-
- #define MAXCLINES 1000
-
- int nlabels=0;
- int nlinks =0;
- int nvars =0;
- int nlines =0;
- int resolve=0;
- int pline =0;
- int cerror =0;
-
- LINK {
- char label[20];
- };
-
- LINE {
- WORD w_command;
- int phyline;
- ARG arg1, arg2, arg3, arg4;
- };
-
- LABEL {
- int n_lineref;
- char c_label[20];
- };
-
- LINK link[100];
- p_LINE line[MAXCLINES];
- LINE cline;
- LABEL labels[100];
-
- BOOL b_append = FALSE;
- BOOL b_good_pass = TRUE;
-
- WINDOW w3;
-
- PSTR errormess[] = {
- "COMPILER ERROR",
- "Symbol exists",
- "Symbol table overflow",
- "Symbol undefined",
- "Syntax error or no argument",
- "Symbol required as first argument",
- "Label already used",
- "Line reference not allowed as arg",
- "Line reference required",
- ""
- };
-
- #define _SYMUSED 1
- #define _VAROVER 2
- #define _UNDEF 3
- #define _SYNTAX 4
- #define _SYMREQ1 5
- #define _LABELUSED 6
- #define _NOLINE 7
- #define _LINEMUST 8
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void v_parse_main(PSTR s);
- * PURPOSE : Parser program start
- * :
- * CREATION: 11/28/1988 06:59:16
- */
- void v_parse_main(PSTR s)
- {
-
- v_open_window(&w3,10,4,70,20);
-
- textcolor(LIGHTGRAY); textbackground(BLACK);
- gotoxy(30,4); cprintf(" %s ",s);
-
- window(11,5,69,20);
- textcolor(YELLOW); textbackground(BLUE);
-
- nlabels=0;
- nlinks =0;
- nvars =0;
- nlines =0;
- resolve=0;
- pline =0;
- b_append = FALSE;
- b_good_pass = TRUE;
-
- v_begin_parse(s);
-
- if (b_good_pass)
- v_write_code(s);
-
- v_free_compiler_ram();
-
- gotoxy(1,15);
- cprintf("%s : PRESS ENTER",(b_good_pass) ? "SUCCESS" : "FAILURE");
- getchar();
-
- v_close_window(&w3);
-
- window(1,1,80,25);
-
- } /* void void v_parse_main(PSTR s); */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void v_begin_parse(PSTR fn)
- * PURPOSE : Open file fn and begin parsing
- * :
- * CREATION: 11/28/1988 07:01:42
- */
- void v_begin_parse(PSTR fn)
- {
- FILE *fp;
- char c_copy[100], c_buf[100], *p;
- int a;
-
- if ((fp=fopen(fn,"rt"))==NULL) {
- cprintf("\n\rCannot open \"%s\" for input\n\r",fn);
- b_good_pass=FALSE;
- } else {
-
- while (fgets(c_buf,100,fp)) {
- pline++;
-
- strcpy(c_copy,c_buf);
-
- p=c_buf;
- while ((*p)!=';' && (*p)) p++;
- if ((*p)==';')
- (*p)=NULL;
-
- cline.phyline =pline;
- cline.w_command =UNUSED;
- cline.arg1.n_ArgType=UNUSED;
- cline.arg1.n_value =UNUSED;
- cline.arg2.n_ArgType=UNUSED;
- cline.arg2.n_value =UNUSED;
- cline.arg3.n_ArgType=UNUSED;
- cline.arg3.n_value =UNUSED;
-
- switch (w_parse(c_buf)) {
- case 0 : if (b_append) {
- if (nlines>MAXCLINES) {
- printf("Too many lines for compiler\n");
- exit(1);
- }
- if ((line[nlines] = (p_LINE) malloc(sizeof(LINE)))==NULL) {
- printf("Cannot malloc ram for source code\n");
- exit(1);
- }
- memcpy(line[nlines++],&cline,sizeof(LINE));
- }
- break;
- default: cprintf("%s (%d): %s\r",errormess[cerror],pline,c_copy);
- b_good_pass=FALSE;
- break;
- }
- }
- fclose(fp);
-
- v_conclude_resolves();
-
- }
- } /* void v_begin_parse(PSTR fn) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> WORD w_parse(PSTR s)
- * PURPOSE : Break down string s into it's component parts
- * :
- * CREATION: 11/28/1988 07:32:08
- */
- WORD w_parse(PSTR s)
- {
- PSTR p;
- char t[20][20];
- WORD wc, werror;
- int a;
-
- strupr(s);
-
- memset(t,0,sizeof(t));
-
- p = strtok(s," ,\n\t");
- wc=0;
-
- while (p!=NULL) {
- strcpy(t[wc++],p);
- p = strtok(NULL," ,\n\t");
- }
-
- b_append=TRUE;
-
- if (wc>0)
- werror=w_fill_structure(t);
- else {
- werror=0; b_append=FALSE;
- }
-
- return werror;
- } /* WORD w_parse(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> WORD w_fill_structure(char t[20][20])
- * PURPOSE : Fills a structure with the tokens passed
- * :
- * CREATION: 11/28/1988 07:53:00
- */
- WORD w_fill_structure(char t[20][20])
- {
- WORD w_return=0;
-
- if (t[0][0]==':') { /* New line ref */
- b_append=FALSE;
- if (!b_add_label(t[0]))
- w_return=1;
- } else if (strcmp(t[0],"MAKE")==0) { /* make */
- b_append=FALSE;
- if (!b_add_symbol(t[1]))
- w_return=1;
- } else if (strcmp(t[0],"RADAR")==0) { /* radar */
- if (!b_make_radar(t[1]))
- w_return=1;
- } else if (strcmp(t[0],"SCAN")==0) { /* scan */
- if (!b_make_scan(t[1],t[2]))
- w_return=1;
- } else if (strcmp(t[0],"WHEREX")==0) { /* wherex */
- if (!b_store_x(t[1]))
- w_return=1;
- } else if (strcmp(t[0],"WHEREY")==0) { /* wherey */
- if (!b_store_y(t[1]))
- w_return=1;
- } else if (strcmp(t[0],"CGDIR")==0) { /* cgdir */
- if (!b_curr_gun(t[1]))
- w_return=1;
- } else if (strcmp(t[0],"CTDIR")==0) { /* ctdir */
- if (!b_curr_tank(t[1]))
- w_return=1;
- } else if (strcmp(t[0],"SELECT")==0) { /* select */
- if (!b_select_weapon(t[1]))
- w_return=1;
- } else if (strcmp(t[0],"JEQ")==0) { /* jeq */
- if (!b_cond_jump(_JUMPEQ,t[1],t[2],t[3]))
- w_return=1;
- } else if (strcmp(t[0],"JLT")==0) { /* jlt */
- if (!b_cond_jump(_JUMPLESS,t[1],t[2],t[3]))
- w_return=1;
- } else if (strcmp(t[0],"JNEQ")==0) { /* jneq */
- if (!b_cond_jump(_JUMPNEQ,t[1],t[2],t[3]))
- w_return=1;
- } else if (strcmp(t[0],"JGT")==0) { /* jgt */
- if (!b_cond_jump(_JUMPGRT,t[1],t[2],t[3]))
- w_return=1;
- } else if (strcmp(t[0],"LEFT")==0) { /* left */
- if (!b_turn_left())
- w_return=1;
- } else if (strcmp(t[0],"RIGHT")==0) { /* right */
- if (!b_turn_right())
- w_return=1;
- } else if (strcmp(t[0],"GLEFT")==0) { /* gleft */
- if (!b_turn_gleft())
- w_return=1;
- } else if (strcmp(t[0],"GRIGHT")==0) { /* gright */
- if (!b_turn_gright())
- w_return=1;
- } else if (strcmp(t[0],"SET")==0) { /* set */
- if (!b_do_set(t[1],t[2]))
- w_return=1;
- } else if (strcmp(t[0],"ADD")==0) { /* add */
- if (!b_do_add(t[1],t[2]))
- w_return=1;
- } else if (strcmp(t[0],"RAND")==0) { /* rand */
- if (!b_do_rand(t[1],t[2]))
- w_return=1;
- } else if (strcmp(t[0],"MOVE")==0) { /* move */
- if (!b_do_move())
- w_return=1;
- } else if (strcmp(t[0],"GOTO")==0) { /* goto */
- if (!b_normal_jump(_JUMP,t[1]))
- w_return=1;
- } else if (strcmp(t[0],"FIRE")==0) { /* fire */
- if (!b_do_fire())
- w_return=1;
- } else if (strcmp(t[0],"CALL")==0) { /* call */
- if (!b_normal_jump(_CALL,t[1]))
- w_return=1;
- } else if (strcmp(t[0],"LOADED")==0) { /* loaded */
- if (!b_loaded(t[1]))
- w_return=1;
- } else if (strcmp(t[0],"RETURN")==0) /* return */
- b_do_return();
- else {
- cerror=_SYNTAX;
- w_return=1;
- }
-
- return w_return;
- } /* WORD w_fill_structure(char t[20][20]) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_add_symbol(PSTR p)
- * PURPOSE : Add symbol p to symbol table
- * : return FALSE if couldn't be added
- * CREATION: 11/28/1988 08:25:06
- */
- BOOL b_add_symbol(PSTR p)
- {
- if (nvars>=100) {
- cerror=_VAROVER;
- return FALSE;
- }
-
- if (n_find_symbol(p) != UNUSED) {
- cerror=_SYMUSED;
- return FALSE;
- }
-
- strcpy(vars[nvars++],p);
-
- return TRUE;
- } /* BOOL b_add_symbol(PSTR p) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> int n_find_symbol(PSTR s)
- * PURPOSE : Searchs symbol table to find s
- * :
- * CREATION: 11/28/1988 08:48:55
- */
- int n_find_symbol(PSTR s)
- {
- int a;
-
- for (a=0; a<nvars; a++)
- if (strcmp(vars[a],s)==0)
- return a;
-
- return UNUSED;
- } /* int n_find_symbol(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_store_x(PSTR s)
- * PURPOSE : Store X location in symbol S
- * :
- * CREATION: 11/28/1988 09:17:51
- */
- BOOL b_store_x(PSTR s)
- {
- int n_sym;
-
- n_sym=n_find_symbol(s);
- if (n_sym==UNUSED) {
- cerror=_UNDEF;
- return FALSE;
- }
-
- cline.w_command=_WHEREX;
- if (!b_parse_arg(&cline.arg1,s)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- } else
- return TRUE;
- } /* BOOL b_store_x(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_curr_gun(PSTR s)
- * PURPOSE : Store current gun position
- * :
- * CREATION: 12/05/1988 17:43:11
- */
- BOOL b_curr_gun(PSTR s)
- {
- int n_sym;
-
- n_sym=n_find_symbol(s);
- if (n_sym==UNUSED) {
- cerror=_UNDEF;
- return FALSE;
- }
-
- cline.w_command=_CGDIR;
- if (!b_parse_arg(&cline.arg1,s)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- } else
- return TRUE;
- } /* BOOL b_curr_gun(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_curr_tank(PSTR s)
- * PURPOSE : Store current tank direction
- * :
- * CREATION: 12/05/1988 17:45:36
- */
- BOOL b_curr_tank(PSTR s)
- {
- int n_sym;
-
- n_sym=n_find_symbol(s);
- if (n_sym==UNUSED) {
- cerror=_UNDEF;
- return FALSE;
- }
-
- cline.w_command=_CTDIR;
- if (!b_parse_arg(&cline.arg1,s)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- } else
- return TRUE;
- } /* BOOL b_curr_tank(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_select_weapon(PSTR s)
- * PURPOSE : Select current weapon
- * :
- * CREATION: 12/05/1988 17:46:57
- */
- BOOL b_select_weapon(PSTR s)
- {
- cline.w_command=_SELECT;
- if (!b_parse_arg(&cline.arg1,s)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- return TRUE;
- } /* BOOL b_select_weapon(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_store_y(PSTR s)
- * PURPOSE : Store current Y location in symbol S
- * :
- * CREATION: 11/28/1988 09:40:04
- */
- BOOL b_store_y(PSTR s)
- {
- int n_sym;
-
- n_sym=n_find_symbol(s);
- if (n_sym==UNUSED) {
- cerror=_UNDEF;
- return FALSE;
- }
-
- cline.w_command=_WHEREY;
- if (!b_parse_arg(&cline.arg1,s)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- } else
- return TRUE;
- } /* BOOL b_store_y(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_turn_left(void)
- * PURPOSE : Turn tank counter-clockwise
- * :
- * CREATION: 12/05/1988 17:25:54
- */
- BOOL b_turn_left(void)
- {
- cline.w_command=_LEFT;
- return TRUE;
- } /* BOOL b_turn_left(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_turn_right(void)
- * PURPOSE : Turn tank clockwise
- * :
- * CREATION: 12/05/1988 17:26:45
- */
- BOOL b_turn_right(void)
- {
- cline.w_command=_RIGHT;
- return TRUE;
- } /* BOOL b_turn_right(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_turn_gleft(void)
- * PURPOSE : aim gun counterclockwise
- * :
- * CREATION: 12/05/1988 17:29:01
- */
- BOOL b_turn_gleft(void)
- {
- cline.w_command=_GLEFT;
- return TRUE;
- } /* BOOL b_turn_gleft(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_turn_gright(void)
- * PURPOSE : aim gun clockwise
- * :
- * CREATION: 12/05/1988 17:38:18
- */
- BOOL b_turn_gright(void)
- {
- cline.w_command=_GRIGHT;
- return TRUE;
- } /* BOOL b_turn_gright(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_parse_arg(p_ARG parg, PSTR s)
- * PURPOSE : Parse out an argument as a constant, variable or
- * : line number
- * CREATION: 11/28/1988 12:02:30
- */
- BOOL b_parse_arg(p_ARG parg, PSTR s)
- {
- BOOL ret;
-
- if (!s) return FALSE;
-
- if (s[0]==':') {
- parg->n_ArgType=LINEREF;
- if ((parg->n_value=n_find_label(s))==UNUSED)
- v_add_resolve(s);
- ret = TRUE;
- } else if (s[0]=='-' || (s[0]>='0' && s[0]<='9')) {
- parg->n_ArgType=CONSTANT;
- parg->n_value=atoi(s);
- ret=TRUE;
- } else {
- parg->n_ArgType=SYMBOL;
- parg->n_value=n_find_symbol(s);
- ret = (parg->n_value==UNUSED) ? FALSE : TRUE;
- }
-
- return ret;
- } /* BOOL b_parse_arg(p_ARG parg, PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_add_label(PSTR p)
- * PURPOSE : Add line label P to list
- * :
- * CREATION: 11/28/1988 12:32:15
- */
- BOOL b_add_label(PSTR p)
- {
- if (n_find_label(p)!=UNUSED) {
- cerror=_LABELUSED;
- return FALSE;
- }
-
- labels[nlabels].n_lineref=nlines;
- strcpy(labels[nlabels++].c_label,p);
-
- return TRUE;
- } /* BOOL b_add_label(PSTR p) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> int n_find_label(PSTR p)
- * PURPOSE : Find line reference P in list
- * : returns UNUSED if not found
- * CREATION: 11/28/1988 12:36:55
- */
- int n_find_label(PSTR p)
- {
- int a;
-
- for (a=0; a<nlabels; a++)
- if (strcmp(labels[a].c_label,p)==0)
- return labels[a].n_lineref;
-
- return UNUSED;
- } /* int n_find_label(PSTR p) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_cond_jump(int ntype,PSTR s1, PSTR s2, PSTR s3)
- * PURPOSE : Do a ntype conditional jump with arguments s1,s2,s3
- * :
- * CREATION: 11/28/1988 12:47:55
- */
- BOOL b_cond_jump(int ntype,PSTR s1, PSTR s2, PSTR s3)
- {
- if (!b_parse_arg(&cline.arg1,s1) ||
- !b_parse_arg(&cline.arg2,s2) ||
- !b_parse_arg(&cline.arg3,s3)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType==LINEREF ||
- cline.arg2.n_ArgType==LINEREF) {
- cerror=_NOLINE;
- return FALSE;
- }
- if (cline.arg3.n_ArgType!=LINEREF) {
- cerror=_LINEMUST;
- return FALSE;
- }
- cline.w_command=ntype;
-
- return TRUE;
- } /* BOOL b_cond_jump(int ntype,PSTR s1, PSTR s2, PSTR s3) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_normal_jump(int ntype, PSTR s)
- * PURPOSE : Do a normal jump command
- * :
- * CREATION: 11/28/1988 12:59:10
- */
- BOOL b_normal_jump(int ntype, PSTR s)
- {
- if (!b_parse_arg(&cline.arg1,s)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=LINEREF) {
- cerror=_LINEMUST;
- return FALSE;
- }
-
- cline.w_command=ntype;
-
- return TRUE;
- } /* BOOL b_normal_jump(int ntype, PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_do_move(void)
- * PURPOSE : Do a move in current direction
- * :
- * CREATION: 11/28/1988 13:08:14
- */
- BOOL b_do_move(void)
- {
- cline.w_command=_MOVE;
- return TRUE;
- } /* BOOL b_do_move(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_do_fire(void)
- * PURPOSE : Fire in current direction
- * :
- * CREATION: 11/28/1988 13:19:04
- */
- BOOL b_do_fire(void)
- {
- cline.w_command=_FIRE;
- return TRUE;
- } /* BOOL b_do_fire(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_loaded(PSTR s)
- * PURPOSE : Check that G is loaded, place answer in S
- * :
- * CREATION: 11/28/1988 13:20:32
- */
- BOOL b_loaded(PSTR s)
- {
- if (!b_parse_arg(&cline.arg1,s)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- }
-
- cline.w_command=_LOADED;
- return TRUE;
- } /* BOOL b_loaded(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_do_return(void)
- * PURPOSE : Do a return statement
- * :
- * CREATION: 11/28/1988 13:32:35
- */
- BOOL b_do_return(void)
- {
- cline.w_command=_RETURN;
- return TRUE;
- } /* BOOL b_do_return(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void v_add_resolve(PSTR s)
- * PURPOSE : Add lineref for future resolution
- * :
- * CREATION: 11/29/1988 07:03:11
- */
- void v_add_resolve(PSTR s)
- {
- strcpy(link[nlinks++].label,s);
- } /* void v_add_resolve(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void v_conclude_resolves(void)
- * PURPOSE : Conclude linking procedure
- * :
- * CREATION: 11/29/1988 10:53:55
- */
- void v_conclude_resolves(void)
- {
- int a;
-
- for (a=0; a<nlines; a++) {
- v_check_link(&line[a]->arg1);
- v_check_link(&line[a]->arg2);
- v_check_link(&line[a]->arg3);
- }
- } /* void v_conclude_resolves(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void v_check_link(p_ARG parg)
- * PURPOSE : Check if argument is an unresolved line reference
- * :
- * CREATION: 11/29/1988 10:56:39
- */
- void v_check_link(p_ARG parg)
- {
- char s[20];
- int a;
-
- if (parg->n_ArgType!=LINEREF || parg->n_value!=UNUSED)
- return;
-
- strcpy(s,link[resolve++].label);
-
- a=n_find_label(s);
-
- if (a==UNUSED)
- cprintf("Unresolved reference \"%s\"\n\r",s);
- else
- parg->n_value=a;
-
- } /* void v_check_link(p_ARG parg) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void v_list_structure(void)
- * PURPOSE : List internal data structure to screen
- * :
- * CREATION: 11/29/1988 11:28:43
- */
- void v_list_structure(void)
- {
- int a;
-
- cprintf("\n\r------ SYMBOLS ---------\n\r");
- for (a=0; a<nvars; a++) cprintf("%2d, %s\n\r",a,vars[a]);
- cprintf("\n\r----- RESOLVES ---------\n\r");
- for (a=0; a<nlinks; a++) cprintf("%2d, %s\n\r",a,link[a].label);
- cprintf("\n\r----- LABELS ---------\n\r");
- for (a=0; a<nlabels; a++) cprintf("%2d, %s\n\r",a,labels[a].c_label);
- cprintf("\n\r----- LINES ----------\n\r");
- for (a=0; a<nlines; a++) cprintf("%2d, %d (%d) (%d) (%d)\n\r",a,line[a]->w_command,
- line[a]->arg1.n_value,
- line[a]->arg2.n_value,
- line[a]->arg3.n_value);
-
- } /* void v_list_structure(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void v_write_code(PSTR s)
- * PURPOSE : Write Binary data to disk
- * :
- * CREATION: 11/29/1988 11:30:15
- */
- void v_write_code(PSTR s)
- {
- FILE *fp;
- int a;
- char drive[10], dir[60], name[20], ext[10];
-
- fnsplit(s,drive,dir,name,ext);
-
- if ((fp=fopen(strcat(name,".BIN"),"wb"))==NULL) {
- cprintf("Cannot open %s to output\n\r",name);
- b_good_pass=FALSE;
- } else {
-
- putw(nlines,fp);
- for (a=0; a<nlines; a++) {
- putw(line[a]->w_command,fp); putw(line[a]->phyline,fp);
- putw(line[a]->arg1.n_ArgType,fp); putw(line[a]->arg1.n_value,fp);
- putw(line[a]->arg2.n_ArgType,fp); putw(line[a]->arg2.n_value,fp);
- putw(line[a]->arg3.n_ArgType,fp); putw(line[a]->arg3.n_value,fp);
- }
-
- fclose(fp);
- }
- } /* void v_write_code(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_do_set(PSTR s1, PSTR s2)
- * PURPOSE : Set s1 to s2
- * :
- * CREATION: 11/29/1988 19:15:45
- */
- BOOL b_do_set(PSTR s1, PSTR s2)
- {
- if (!b_parse_arg(&cline.arg1,s1)) {
- cerror=_SYNTAX;
- return FALSE;
- }
- if (!b_parse_arg(&cline.arg2,s2)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- }
-
- cline.w_command=_SET;
- return TRUE;
-
- } /* BOOL b_do_set(PSTR s1, PSTR s2) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s>BOOL b_do_add(PSTR s1, PSTR s2)
- * PURPOSE : Add an argument to a symbol
- * :
- * CREATION: 12/02/1988 10:01:44
- */
- BOOL b_do_add(PSTR s1, PSTR s2)
- {
- if (!b_parse_arg(&cline.arg1,s1)) {
- cerror=_SYNTAX;
- return FALSE;
- }
- if (!b_parse_arg(&cline.arg2,s2)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- }
-
- cline.w_command=_ADD;
- return TRUE;
-
- } /* BOOL b_do_add(PSTR s1, PSTR s2) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_do_rand(PSTR s1, PSTR s2)
- * PURPOSE : Set s1 to a random number within 1-s2
- * :
- * CREATION: 12/02/1988 10:02:41
- */
- BOOL b_do_rand(PSTR s1, PSTR s2)
- {
- if (!b_parse_arg(&cline.arg1,s1)) {
- cerror=_SYNTAX;
- return FALSE;
- }
- if (!b_parse_arg(&cline.arg2,s2)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- }
-
- cline.w_command=_RAND;
- return TRUE;
-
- } /* BOOL b_do_rand(PSTR s1, PSTR s2) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void v_free_compiler_ram(void)
- * PURPOSE : Free up ram used by compiler
- * :
- * CREATION: 12/05/1988 16:25:19
- */
- void v_free_compiler_ram(void)
- {
- int a;
-
- for (a=0; a<nlines; a++)
- free(line[a]);
- } /* void v_free_compiler_ram(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_make_radar(PSTR s)
- * PURPOSE : Do a radar command
- * :
- * CREATION: 12/06/1988 11:44:45
- */
- BOOL b_make_radar(PSTR s)
- {
- if (!b_parse_arg(&cline.arg1,s)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- }
-
- cline.w_command=_RADAR;
- return TRUE;
- } /* BOOL b_make_radar(PSTR s) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> BOOL b_make_scan(PSTR s1, PSTR s2)
- * PURPOSE : Do a SCAN command
- * :
- * CREATION: 12/06/1988 11:45:08
- */
- BOOL b_make_scan(PSTR s1, PSTR s2)
- {
- if (!b_parse_arg(&cline.arg1,s1)) {
- cerror=_SYNTAX;
- return FALSE;
- }
- if (!b_parse_arg(&cline.arg2,s2)) {
- cerror=_SYNTAX;
- return FALSE;
- }
-
- if (cline.arg1.n_ArgType!=SYMBOL) {
- cerror=_SYMREQ1;
- return FALSE;
- }
-
- cline.w_command=_SCAN;
- return TRUE;
- } /* BOOL b_make_scan(PSTR s1, PSTR s2) */